from book import ContentType

class Model:
    def make_text_prompt(self, text: str, target_language: str) -> str:
        return f"Translate the following paragraph into {target_language}：\n{text}"

    def make_table_prompt(self, table: str, target_language: str) -> str:
        return f"""Translated as {target_language}, maintain spacing (spaces, separators, commas), and return in tabular form。
                   example:[Fruit, Color, Price (USD)] [Apple, Red, 1.20] 
                   tanslation:
                   水果     颜色   价格（USD）
                   苹果     红色    1.20
                   The following is the content that needs to be translated:
                   {table}"""

    def translate_prompt(self, content, target_language: str) -> str:
        if content.content_type == ContentType.TEXT:
            return self.make_text_prompt(content.original, target_language)
        elif content.content_type == ContentType.TABLE:
            return self.make_table_prompt(content.get_original_as_str(), target_language)

    def make_request(self, prompt):
        raise NotImplementedError("子类必须实现 make_request 方法")
